//Programs TABLE1A and TABLE1B produce the results in TABLE 1.
//The programs are intended to be run in tandem, with program A run first.
//It takes approximately 40 minutes on a laptop to run 10,000 iterations.


clear
set more off
log using "\\file\UsersW$\wrr15\Home\My Documents\My Files\HURWICZ BIAS\REVISION FOR ECONOMIC MODELLING\PROGRAMS2\TABLE1.smcl", replace
etime, start
drop _all
graph drop _all
set seed 13
matrix meanbhaty = J(5,5,0)
matrix meanRR = J(5,5,0)

local i = 1
foreach betay in 0.60 0.70 0.80 0.90 0.95 {
   local j = 1
   foreach smallobs in 10 30 50 100 1000 {
      simulate bhaty = r(bhaty) pvalue = r(pvalue), ///
         reps(10000): hurwicz, betay(`betay') smallobs(`smallobs') bigobs(1100) ///
		 beta0(0) betau(1)
      summ bhaty, meanonly
      matrix meanbhaty[`i', `j'] = r(mean)
	  generate RejectRate = 0
      replace RejectRate = 1 if pvalue < 0.05  
	  summ RejectRate, meanonly
      matrix meanRR[`i', `j'] = r(mean)
      local `++j'
   }
   local `++i'
}
matrix colnames meanbhaty = T10 T30 T50 T100 T1000
matrix rownames meanbhaty= B60 B70 B80 B90 B95
matrix colnames meanRR = T10 T30 T50 T100 T1000
matrix rownames meanRR = B60 B70 B80 B90 B95
matrix list meanbhaty
matrix list meanRR
etime
log close
